import axios from "axios";
// 创建axios 请求库

import { ElMessage } from "element-plus";

const request = axios.create({
    baseURL : '/api',
    timeout:5000
})
// 请求拦截器
request.interceptors.request.use((config) => {
    return config
},(error) => {
    return Promise.reject(error)
})
// 响应拦截器
request.interceptors.response.use((response) => {

    if (response.data.code !== 200) {
        ElMessage({
            type:"error",
            message:response.data.message
        })
        return Promise.reject(response.data)
    }
    return response.data
},(error) => {
    console.log(error);
    ElMessage({
        type:"error",
        message:error.message
    })
    return Promise.reject(error)
})

export default request